package org.tc.product.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.tc.product.entity.Commoditys;
import org.tc.product.mapper.CommoditysMapper;
import org.tc.product.service.CommoditysService;
import org.tc.product.util.PageHelper;

import java.util.List;

@RestController
public class CommoditysServiceImpl implements CommoditysService {

    @Autowired
    private CommoditysMapper commoditysMapper;

    @Override
    public PageHelper<Commoditys> selectAllCom(int pageNo, int pageSize, Integer storeid, Integer state,String brand) {
        PageHelper<Commoditys> pageHelper = new PageHelper<>();
        pageHelper.setPageNo(pageNo);
        pageHelper.setPageSize(pageSize);
        List<Commoditys> slist = commoditysMapper.selectAll(pageHelper.getFirstResult(), pageHelper.getPageSize(), storeid,brand);
        pageHelper.setData(slist);
        int sumCount = commoditysMapper.getComCount(storeid, state);
        int pageCount = sumCount % pageSize == 0 ? sumCount / pageSize : sumCount / pageSize + 1;
        pageHelper.setPageCount(sumCount);
        return pageHelper;
    }

    @Override
    public Commoditys selectComById(Integer id) {
        Commoditys c = commoditysMapper.selectComById(id);
        return c;
    }

    @Override
    public List<Commoditys> selectBrand( Integer classoneid,  Integer classtweid,Integer classthreeid) {
        return commoditysMapper.selectBrand(classoneid, classtweid, classthreeid);
    }

    @Override
    public int updcom(@RequestBody Commoditys commoditys) {
        int count = commoditysMapper.updcom(commoditys);
        return count;
    }

    @Override
    public Integer insertCom(@RequestBody Commoditys record) {
        record.setShoppingnumber(0);
        int count = commoditysMapper.insertCom(record);
        Integer id = null;
        if (count == 1) {
            id = commoditysMapper.getLastId();
        }
        return id;
    }

    @Override
    public List<Commoditys> getAllCom(Integer storeid) {
        return commoditysMapper.getAllCom(storeid);
    }

    @Override
    public int getIdByName(String name, Integer storeid) {
        int id = commoditysMapper.getIdByName(name, storeid);
        return id;
    }

    @Override
    public List<Commoditys> getComByClass(@RequestBody Commoditys record) {
        List<Commoditys> list = commoditysMapper.getComByClass(record);
        return list;
    }

    @Override
    public int QuerytoSalea(Integer id, Integer storeid) {
        return commoditysMapper.QuerytoSalea(id, storeid);
    }

    @Override
    public int UpdtoSalea(Integer stock,Integer id, Integer storeid) {
        return commoditysMapper.UpdtoSalea(stock,id, storeid);
    }

    @Override
    public int UpdtoPro(Integer stock, Integer commid) {
        return commoditysMapper.UpdtoPro(stock, commid);
    }

    @Override
    public List<Commoditys> QueryMem(Integer storeid) {
        return commoditysMapper.QueryMem(storeid);
    }

    @Override
    public List<Commoditys> QueryAllMem(Integer storeid) {
        return commoditysMapper.QueryAllMem(storeid);
    }
}
